<%- include('nav') %>
<div class="text-sm breadcrumbs">
  <ul>
    <li>
      <a href="/admin/home">首页</a>
    </li>
    <li>设置</li>
  </ul>
</div>

<div id="app">
  <div class="col col-6 p1">
    <div class="card bg-white">
      <div class="card-body">
        <div class="card-title">新建兑换码</div>

        <div class="form-control">
          <label class="label">
            <span class="label-text">描述</span>
          </label>
          <input
            type="text"
            v-model="redeem.title"
            placeholder="输入兑换码备注信息"
            class="input input-sm input-bordered"
          />
        </div>

        <div class="form-control">
          <label class="label">
            <span class="label-text">数量</span>
          </label>
          <input type="number" v-model="redeem.num" placeholder="输入生成数量" class="input input-sm input-bordered" />
        </div>

        <div class="form-control">
          <label class="label">
            <span class="label-text">兑换天数</span>
          </label>
          <input type="number" v-model="redeem.days" placeholder="输入兑换天数" class="input input-sm input-bordered" />
        </div>

        <div class="card-actions">
          <button class="btn btn-primary btn-small" @click="generate">生成</button>
        </div>
      </div>
    </div>
  </div>
  <script>
    new Vue({
      el: "#app",
      data: function () {
        return {
          redeem: {
            title: "",
            num: 10,
            days: 30,
          },
        };
      },
      methods: {
        generate: function () {
          axios.post("/admin/redeem/generate", this.redeem).then(function (res) {
            if (res.data.status) {
              alert("生成成功");
              location.href = "/admin/page/redeems";
            } else {
              weui.topTips(res.data.msg);
            }
          });
        },
      },
    });
  </script>
</div>
